home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!news
- From: identd@ix.netcom.com(none )
- Newsgroups: comp.lang.c
- Subject: Re: rand() source
- Date: 11 Apr 1996 23:37:59 GMT
- Organization: Netcom
- Message-ID: <4kk54n$m8k@dfw-ixnews2.ix.netcom.com>
- References: <4kf88n$j5e@news.ualr.edu>
- NNTP-Posting-Host: sea-wa11-16.ix.netcom.com
- X-NETCOM-Date: Thu Apr 11 6:37:59 PM CDT 1996
-
- In <4kf88n$j5e@news.ualr.edu> luchini@hybrid.ualr.edu (Dr. Chris
- Luchini) writes:
- >
- >does anyone have the source for the ran() or rand() functions?
- >I could really use it ASAP!
- >-c
- >
- >--
- > Chris Luchini, University of Arkansas at Little Rock, Hybrid Rocket
- Lab
- >575 ETAS, 2801 S. University, Little Rock, AR 72204 (501) 569 8442
- fax-8020
-
- I don't know if this is the source your thinking of... but here is
- something off of the top of my head to make random numbers. there is
- probably an easier way but I haven't been coding long:
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
-
- int rnd(int range);
- void seedrd(void);
-
- main()
- {
- int x;
- seedrnd();
-
- /*
- * display a hundred random numbers
- */
-
- for(x=0;x<100;x++)
- printf("%i\n",rnd(10));
- }
-
- int rnd(int range)
- {
- int r;
-
- r=rand()%range;
- return(r);
- }
-
- void seedrnd(void)
- {
- srand((unsigned)time(NULL));
- }
-
- /*
- * i just realized as I typed this off of the top of my head that you
- * wanted the source to the actual rand() function. oops. may as well
- * post it anyways. :-) sorry.
- */
-
-